package com.cicc.springboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cicc.springboot.common.dto.R;
import com.cicc.springboot.entity.PurchaseOrderEntity;
import com.cicc.springboot.model.PurchaseOrderQuery;
import com.cicc.springboot.service.PurchaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName PurchaseOrder
 * @Description TODO
 * @Author 转轮王
 * @Date 2024/9/30 16:01
 * @Version 1.0
 */

@RestController
public class PurchaseOrderController {

    @Autowired
    private PurchaseOrderService purchaseOrderService;


    /**
     * 分页展示订单信息
     */
    @GetMapping("/purchaseOrder")
    public R<Page<PurchaseOrderEntity>> queryPurchaseOrderPage(@RequestParam("currentPage") int currentPage,
                                                               @RequestParam("pageSize") int pageSize,
                                                               @RequestParam(value = "createTimeStart", required = false) String createTimeStart,
                                                               @RequestParam(value = "createTimeEnd", required = false) String createTimeEnd,
                                                               @RequestParam(value = "supplierName", required = false) String supplierName,
                                                               @RequestParam(value = "supplierCode", required = false) String supplierCode) {

        return purchaseOrderService.queryPurchaseOrderPage(currentPage, pageSize, createTimeStart, createTimeEnd, supplierName, supplierCode);
    }

    /**
     * 新增或修改采购订单信息
     */
    @PostMapping("/savePurchaseOrder")
    public R<String> savePurchaseOrder(@RequestBody PurchaseOrderQuery purchaseOrderQuery) {
        return purchaseOrderService.savePurchaseOrder(purchaseOrderQuery);
    }

    /**
     * 删除采购订单
     */
    @DeleteMapping("/deletePurchaseOrder")
    public R<String> deletePurchaseOrder(@RequestParam("id") long id) {
        return purchaseOrderService.deletePurchaseOrder(id);
    }

    /**
     * 查询全部供应商
     */

    @GetMapping("/queryAllSupplierName")
    public R<String[]> queryAllSupplierName() {
        return purchaseOrderService.queryAllSupplierName();
    }

    /**
     * 根据供应商的名称获取供应商的编码
     */
    @GetMapping("/querySupplierCodeByName")
    public R<String> querySupplierCodeByName(@RequestParam("supplierName") String supplierName) {
        return purchaseOrderService.querySupplierCodeByName(supplierName);
    }


}
